package com.loozb.thread5.disruptor;

import com.lmax.disruptor.RingBuffer;
import com.loozb.thread4.queue.*;

import java.nio.ByteBuffer;

/**
 * @author 龙召碧
 * @create 2018-02-09 11:06
 **/
public class Producer {

    private RingBuffer<PCData> ringBuffer = null;
    public Producer(RingBuffer<PCData> ringBuffer) {
        this.ringBuffer = ringBuffer;
    }
    public void pushData(ByteBuffer bb) {
        long sequence = ringBuffer.next();
        try {
            PCData event = ringBuffer.get(sequence);
            event.setValue(bb.getLong(0));
        } finally {
            ringBuffer.publish(sequence);
        }

    }
}
